package com.andy.buyu.server.action;

import java.util.List;

import org.springframework.stereotype.Component;

import com.andy.buyu.server.game.FishGame;
import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.socket.GmAction;
import com.andy.buyu.server.socket.MySocketSession;
import com.andy.buyu.server.socket.codec.DataWrap;
import com.andy.buyu.server.utils.CommonUtils;
import com.andy.buyu.server.utils.GoConstant;

/**
 * 开炮逻辑
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_200)
public class Action200 implements IReqAction{

	@Override
	public void doAction(MySocketSession session, DataWrap data) {
		GameUser user = session.getUser();
		int x = data.getInt();
		int y = data.getInt();
//		byte battery = data.getByte();
		
		int battery = user.getBattery();
		FishGame game = user.getGame();
		if(game == null) return;
		if(battery == GoConstant.BATTERY_TYPE_1 || battery == GoConstant.BATTERY_TYPE_2) return;
		boolean isFire = CommonUtils.fire(user, 0, x, y,battery);
		
		// 核弹炮必然打中，同时执行捕鱼逻辑
		if(isFire && battery == GoConstant.BATTERY_TYPE_13){
			if(!user.catchFish(GoConstant.BATTERY_TYPE_13,0)) return ;
			List<Integer> scripts = game.getInFishs();
			CommonUtils.catchMultFish(user, GoConstant.BATTERY_TYPE_13, scripts,0);
			
		}
	}


	
	
	
}
